﻿using System;
using umbraco.cms.businesslogic.datatype;
using umbraco.interfaces;

namespace SoetemanSoftware.Umb.Datatypes.MacroPicker
{
    /// <summary>
    /// Umbraco DataType class
    /// </summary>
    public class MacroPickerDataType : BaseDataType, IDataType
    {
        #region private fields
        private IDataEditor _DataEditor;
        private IData _baseData;
        private MacroPickerPrevalueEditor _prevalueeditor;
        #endregion

        #region IDataType Members

        /// <summary>
        /// Holds a reference to the selected Data
        /// </summary>
        public override IData Data
        {
            get
            {
                if (_baseData == null)
                {
                    _baseData = new DefaultData(this);
                } return _baseData;
            }
        }

        /// <summary>
        /// Holds a reference to the dataEditor (CMS) Class
        /// </summary>
        public override IDataEditor DataEditor
        {
            get
            {
                if (_DataEditor == null)
                {
                    _DataEditor = new MacroPickerDataEditor(Data, ((MacroPickerPrevalueEditor)PrevalueEditor).AllowedMacros);
                }
                return _DataEditor;
            }

        }

        /// <summary>
        /// DataType name to show in the list
        /// </summary>
        public override string DataTypeName
        {
            get { return "Macro Picker"; }
        }

        /// <summary>
        /// Unique ID 
        /// </summary>
        public override Guid Id
        {
            get { return new Guid("2b4a6034-7063-47b0-9c4b-08bf1f23b3e2"); }
        }

        /// <summary>
        /// Reference to the Settings Editor Class
        /// </summary>
        public override IDataPrevalue PrevalueEditor
        {
            get
            {
                if (_prevalueeditor == null)
                {
                    _prevalueeditor = new MacroPickerPrevalueEditor(this);
                }
                return _prevalueeditor;
            }
        }

        #endregion
    }
}
